package fileio_utils;


import java.io.File
import java.lang.String 


case class FU_InvalidPathException (mess : String) extends Exception 


object FILEIO_UTILS {
  // ListAll returns an array of string array (ret_lists)
  // ret_lists[0] is a list of directories 
  // ret_lists[1] is a list of files 
  def ListAll (dir_target : String) : Array[Array[String]] = {
    var ret_lists = Array[Array[String]]()
    ret_lists = (ret_lists :+ Array[String]()) :+ Array[String]()

    val fh = new File(dir_target)
    if (fh.exists() == false) {
      throw new FU_InvalidPathException("Invalid Path : " + dir_target)
    }

    val all_files = fh.listFiles()
    all_files.foreach { af => 
      if (af.isDirectory()) {
	ret_lists(0) = ret_lists(0) :+ af.toString()
      } 
      else { // af is a file 
	ret_lists(1) = ret_lists(1) :+ af.toString()
      }
    }

    ret_lists
  }

  def ListDirs (dir_target : String) : Array[String] = {
    ListAll(dir_target)(0)
  }

  def ListFiles (dir_target : String) : Array[String] = {
    ListAll(dir_target)(1)
  }
}
